package com.medusa.aps.business.modules.modeling.model.input;

import com.medusa.aps.business.modules.modeling.mp.entity.TechnologicalProcess;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

import static com.medusa.aps.business.model.constant.DigitConstants.*;

/**
 * 工艺工序接收实体
 *
 * @author miskw
 * @date 2023/9/2
 */
@Data
@Accessors(chain = true)
public class TechnologicalProcessDTO {
    /**
     * 工序id
     */
    @Schema(description = "工序id")
    @NotNull(message = "工序id不能为空")
    private Integer processId;
    /**
     * 工序号
     */
    @Schema(description = "工序号")
    private Integer processNumber;
    /**
     * 工序编码
     */
    @Schema(description = "工序编码")
    @NotNull(message = "工序编码不能为空")
    private String processCode;
    /**
     * 工序名称
     */
    @Schema(description = "工序名称")
    @NotNull(message = "工序名称不能为空")
    private String processName;
    /**
     * 换型时间
     */
    @Schema(description = "换型时间")
    @Max(value = 9999999L, message = "换型时间" + SEVEN_DIGIT_RANGE_PROMPTS)
    @Min(value = 0, message = "换型时间" + SEVEN_DIGIT_RANGE_PROMPTS)
    private Long replacementTime;
    /**
     * 转运批量
     */
    @Schema(description = "转运批量")
    @NotNull(message = "转运批量不能为空")
    @Max(value = 9999999999L, message = "转运批量" + TEN_DIGIT_RANGE_PROMPTS)
    @Min(value = 1, message = "转运批量" + TEN_DIGIT_RANGE_PROMPTS)
    private Long transshipmentBatch;
    /**
     * 转运时间
     */
    @Schema(description = "转运时间")
    @NotNull(message = "转运时间不能为空")
    @Max(value = 9999999L, message = "转运时间" + SEVEN_DIGIT_RANGE_PROMPTS)
    @Min(value = 1, message = "转运时间" + SEVEN_DIGIT_RANGE_PROMPTS)
    private Long transshipmentTime;
    /**
     * 加工内容
     */
    @Schema(description = "加工内容")
    @Size(max = 50, message = "加工内容最多不能超过50个字")
    private String processingContent;
    /**
     * 工艺工序设备
     */
    @Valid
    @Schema(description = "工艺工序设备")
    @Size(min = 1, message = "工艺工序设备至少一条")
    private List<ProcessEquipmentDTO> processEquipments;

    public TechnologicalProcess toTechnologicalProcess(Integer processRouteId, Long materialId, String materialCode, Integer processNumber) {
        return new TechnologicalProcess()
                .setProcessId(processId)
                .setProcessNumber(processNumber)
                .setProcessCode(processCode)
                .setProcessName(processName)
                .setReplacementTime(replacementTime)
                .setTransshipmentBatch(transshipmentBatch)
                .setTransshipmentTime(transshipmentTime)
                .setProcessingContent(processingContent)
                .setProcessRouteId(processRouteId)
                .setMaterialId(materialId)
                .setMaterialCode(materialCode);
    }
}
